//
//
//  拖料架设置界面
//
//



import QtQuick
import QtQuick.Controls.Material
import QtQuick.Layouts

Item {
    width: rootWidth
    height: rootHeight /*- 150*/

    A_NumberKeyboard{
        id: holdSettingKeyboard
        isDirectOverwrite: false
    }

    Component.onCompleted: {
        // console.log("生成！！ - 拖料架设置")
        Cpp_PLC.QML_CurrentPage = 14;
    }

    // Component.onDestruction: {
    //     console.log("销毁 - 拖料架设置")
    // }


    property bool f_Hold_BackOver_Flag: Cpp_PLC.Front_Hold_BackOver
    property bool m_Hold_BackOver_Flag: Cpp_PLC.Mid_Hold_BackOver
    property bool b_Hold_BackOver_Flag: Cpp_PLC.Back_Hold_BackOver


    Rectangle{
        anchors.top: parent.top
        anchors.topMargin: 10
        anchors.horizontalCenter: parent.horizontalCenter
        width: rootWidth - 20
        height: 400
        color: "transparent"
        border.width: 1


        Item{
            anchors.top: parent.top
            anchors.topMargin: 20
            anchors.horizontalCenter: parent.horizontalCenter
            width: 800
            height: 100


            Rectangle{
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left
                anchors.leftMargin: 30
                width: 50
                height: 50
                radius: 25
                color: f_Hold_BackOver_Flag ? "red" : "white"
            }


            A_Label{
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left
                anchors.leftMargin: 220
                label_Data: qsTr("前 托 料 架")
                // label_pointSize: 40
            }

            A_Button{
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left
                anchors.leftMargin: 550
                // contentText_Fontsize: 30
                contentText_Data: Cpp_PLC.IO_Y15 ?  qsTr("打 开") : qsTr("关 闭")
                contentText_Color: Cpp_PLC.IO_Y15 ?  "red" : "black"

                onButtonPressed: {
                    Cpp_PLC.write_Modbus_RTU_Coils(115,"1")
                }

                onButtonReleased: {
                    Cpp_PLC.write_Modbus_RTU_Coils(115,"0")
                }


            }

        }

        Item{
            anchors.top: parent.top
            anchors.topMargin: 150
            anchors.horizontalCenter: parent.horizontalCenter
            width: 800
            height: 100


            Rectangle{
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left
                anchors.leftMargin: 30
                width: 50
                height: 50
                radius: 25
                color: m_Hold_BackOver_Flag ? "red" : "white"
            }


            A_Label{
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left
                anchors.leftMargin: 220
                label_Data: qsTr("中 托 料 架")
                // label_pointSize: 40
            }

            A_Button{
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left
                anchors.leftMargin: 550
                // contentText_Fontsize: 30
                contentText_Data: Cpp_PLC.IO_Y16 ? qsTr("打 开") : qsTr("关 闭")
                contentText_Color: Cpp_PLC.IO_Y16 ? "red" : "black"

                onButtonPressed: {
                    Cpp_PLC.write_Modbus_RTU_Coils(116,"1")
                }

                onButtonReleased: {
                    Cpp_PLC.write_Modbus_RTU_Coils(116,"0")
                }
            }

        }

        Item{
            anchors.top: parent.top
            anchors.topMargin: 280
            anchors.horizontalCenter: parent.horizontalCenter
            width: 800
            height: 100


            Rectangle{
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left
                anchors.leftMargin: 30
                width: 50
                height: 50
                radius: 25
                color: b_Hold_BackOver_Flag ? "red" : "white"
            }


            A_Label{
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left
                anchors.leftMargin: 220
                label_Data: qsTr("后 托 料 架")
                // label_pointSize: 40
            }

            A_Button{
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left
                anchors.leftMargin: 550
                // contentText_Fontsize: 30
                contentText_Data: Cpp_PLC.IO_Y17 ? qsTr("打 开") : qsTr("关 闭")
                contentText_Color: Cpp_PLC.IO_Y17 ? "red" : "black"

                onButtonPressed: {
                    Cpp_PLC.write_Modbus_RTU_Coils(117,"1")
                }

                onButtonReleased: {
                    Cpp_PLC.write_Modbus_RTU_Coils(117,"0")
                }
            }

        }
    }














    Rectangle{
        anchors.top: parent.top
        anchors.topMargin: 420
        anchors.horizontalCenter: parent.horizontalCenter
        width: rootWidth - 20
        height: 900
        color: "transparent"
        border.width: 1

        Item{
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: parent.top
            anchors.topMargin: 20
            width: 1000
            height: 200

            A_Label{
                anchors.left: parent.left
                anchors.top: parent.top
                anchors.topMargin: 10
                label_Data: qsTr("前托触发点")
            }

            // A_TextInput{
            //     anchors.left: parent.left
            //     anchors.top: parent.top
            //     anchors.topMargin: 100
            //     inputWidth: 300
            //     // maxDataLength: 6
            //     showData: Cpp_PLC.Front_Hold_Location

            //     onInputFinished: {
            //         if( Number(inputData) < 0 )
            //         {
            //             Cpp_PLC.write_Modbus_RTU_Hold_32(1294,"0")
            //         }
            //         else if( Number(inputData) > 999999 )
            //         {
            //             Cpp_PLC.write_Modbus_RTU_Hold_32(1294,"999999")
            //         }
            //         else
            //         {
            //             Cpp_PLC.write_Modbus_RTU_Hold_32(1294,inputData)
            //         }
            //     }
            // }

            A_NumberInput{
                anchors.left: parent.left
                anchors.top: parent.top
                anchors.topMargin: 100
                inputWidth: 300
                text: Cpp_PLC.Front_Hold_Location
                minValue: 0
                maxValue: 999999
                keyboard: holdSettingKeyboard

                onEditingFinished: function(value){
                    Cpp_PLC.write_Modbus_RTU_Hold_32(1294,value)
                }


            }

            A_Button{
                anchors.left: parent.left
                anchors.leftMargin: 810
                anchors.top: parent.top
                anchors.topMargin: 10
                contentText_Data: Cpp_PLC.Front_Hold_Mode ? qsTr("小 于") : qsTr("大 于")
                contentText_Color: Cpp_PLC.Front_Hold_Mode ? "red" : "black"
                // contentText_Fontsize: 40

                onButtonClicked: {
                    if(Cpp_PLC.Front_Hold_Mode)
                    {
                        Cpp_PLC.write_Modbus_RTU_Coils(384,"0")
                    }
                    else
                    {
                        Cpp_PLC.write_Modbus_RTU_Coils(384,"1")
                    }
                }
            }

            A_Button{
                anchors.left: parent.left
                anchors.leftMargin: 810
                anchors.top: parent.top
                anchors.topMargin: 100
                contentText_Data: Cpp_PLC.Front_Hold_Enable ? qsTr("有 效") : qsTr("无 效")
                contentText_Color: Cpp_PLC.Front_Hold_Enable ? "red" : "black"
                // contentText_Fontsize: 40

                onButtonClicked: {
                    if(Cpp_PLC.Front_Hold_Enable)
                    {
                        Cpp_PLC.write_Modbus_RTU_Coils(387,"0")
                    }
                    else
                    {
                        Cpp_PLC.write_Modbus_RTU_Coils(387,"1")
                    }
                }
            }


        }

        Item{
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: parent.top
            anchors.topMargin: 240
            width: 1000
            height: 200

            A_Label{
                anchors.left: parent.left
                anchors.top: parent.top
                anchors.topMargin: 10
                label_Data: qsTr("中托触发点")
            }

            // A_TextInput{
            //     anchors.left: parent.left
            //     anchors.top: parent.top
            //     anchors.topMargin: 100
            //     inputWidth: 230
            //     showData: Cpp_PLC.Mid_Hold_Location_Down_Limit

            //     onInputFinished: {
            //         if(Number(inputData) < 0)
            //         {
            //             Cpp_PLC.write_Modbus_RTU_Hold_32(296,"0")
            //         }
            //         else if(Number(inputData) > 999999)
            //         {
            //             Cpp_PLC.write_Modbus_RTU_Hold_32(296,"999999")
            //         }
            //         else
            //         {
            //             Cpp_PLC.write_Modbus_RTU_Hold_32(296,inputData)
            //         }
            //     }
            // }


            A_NumberInput{
                anchors.left: parent.left
                anchors.top: parent.top
                anchors.topMargin: 100
                inputWidth: 230
                text: Cpp_PLC.Mid_Hold_Location_Down_Limit
                minValue: 0
                maxValue: 999999
                keyboard: holdSettingKeyboard

                onEditingFinished: function(value){
                    Cpp_PLC.write_Modbus_RTU_Hold_32(296,value)
                }


            }

            A_Label{
                anchors.left: parent.left
                anchors.leftMargin: 250
                anchors.top: parent.top
                anchors.topMargin: 100
                labelWidth: 300
                label_Data: qsTr("≤  落下区间  ≤")
            }

            // A_TextInput{
            //     anchors.left: parent.left
            //     anchors.leftMargin: 570
            //     anchors.top: parent.top
            //     anchors.topMargin: 100
            //     inputWidth: 230
            //     showData: Cpp_PLC.Mid_Hold_Location_Up_Limit

            //     onInputFinished: {
            //         if(Number(inputData) < 0)
            //         {
            //             Cpp_PLC.write_Modbus_RTU_Hold_32(1296,"0")
            //         }
            //         else if(Number(inputData) > 999999)
            //         {
            //             Cpp_PLC.write_Modbus_RTU_Hold_32(1296,"999999")
            //         }
            //         else
            //         {
            //             Cpp_PLC.write_Modbus_RTU_Hold_32(1296,inputData)
            //         }
            //     }
            // }


            A_NumberInput{
                anchors.left: parent.left
                anchors.leftMargin: 570
                anchors.top: parent.top
                anchors.topMargin: 100
                inputWidth: 230
                text: Cpp_PLC.Mid_Hold_Location_Up_Limit
                minValue: 0
                maxValue: 999999
                keyboard: holdSettingKeyboard

                onEditingFinished: function(value){
                    Cpp_PLC.write_Modbus_RTU_Hold_32(1296,value)
                }


            }


            A_Button{
                anchors.left: parent.left
                anchors.leftMargin: 810
                anchors.top: parent.top
                anchors.topMargin: 100
                contentText_Data: Cpp_PLC.Mid_Hold_Enable ? qsTr("有 效") : qsTr("无 效")
                contentText_Color: Cpp_PLC.Mid_Hold_Enable ? "red" : "black"
                // contentText_Fontsize: 40

                onButtonClicked: {
                    if(Cpp_PLC.Mid_Hold_Enable)
                    {
                        Cpp_PLC.write_Modbus_RTU_Coils(388,"0")
                    }
                    else
                    {
                        Cpp_PLC.write_Modbus_RTU_Coils(388,"1")
                    }
                }
            }
        }


        Item{
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: parent.top
            anchors.topMargin: 470
            width: 1000
            height: 200

            A_Label{
                anchors.left: parent.left
                anchors.top: parent.top
                anchors.topMargin: 10
                label_Data: qsTr("后托触发点")
            }

            // A_TextInput{
            //     anchors.left: parent.left
            //     anchors.top: parent.top
            //     anchors.topMargin: 100
            //     inputWidth: 300
            //     // maxDataLength: 6
            //     showData: Cpp_PLC.Back_Hold_Location

            //     onInputFinished: {
            //         if(Number(inputData) < 0)
            //         {
            //             Cpp_PLC.write_Modbus_RTU_Hold_32(1298,"0")
            //         }
            //         else if(Number(inputData) > 999999)
            //         {
            //             Cpp_PLC.write_Modbus_RTU_Hold_32(1298,"999999")
            //         }
            //         else
            //         {
            //             Cpp_PLC.write_Modbus_RTU_Hold_32(1298,inputData)
            //         }
            //     }
            // }


            A_NumberInput{
                anchors.left: parent.left
                anchors.top: parent.top
                anchors.topMargin: 100
                inputWidth: 300
                // maxDataLength: 6
                text: Cpp_PLC.Back_Hold_Location
                minValue: 0
                maxValue: 999999
                keyboard: holdSettingKeyboard

                onEditingFinished: function(value){
                    Cpp_PLC.write_Modbus_RTU_Hold_32(1298,value)
                }

            }

            A_Button{
                anchors.left: parent.left
                anchors.leftMargin: 810
                anchors.top: parent.top
                anchors.topMargin: 10
                contentText_Data: Cpp_PLC.Back_Hold_Mode ? qsTr("小 于") : qsTr("大 于")
                contentText_Color: Cpp_PLC.Back_Hold_Mode ? "red" : "black"
                // contentText_Fontsize: 40

                onButtonClicked: {
                    if(Cpp_PLC.Back_Hold_Mode)
                    {
                        Cpp_PLC.write_Modbus_RTU_Coils(386,"0")
                    }
                    else
                    {
                        Cpp_PLC.write_Modbus_RTU_Coils(386,"1")
                    }
                }
            }

            A_Button{
                anchors.left: parent.left
                anchors.leftMargin: 810
                anchors.top: parent.top
                anchors.topMargin: 100
                contentText_Data: Cpp_PLC.Back_Hold_Enable ? qsTr("有 效") : qsTr("无 效")
                contentText_Color: Cpp_PLC.Back_Hold_Enable ? "red" : "black"
                // contentText_Fontsize: 40

                onButtonClicked: {
                    if(Cpp_PLC.Back_Hold_Enable)
                    {
                        Cpp_PLC.write_Modbus_RTU_Coils(389,"0")
                    }
                    else
                    {
                        Cpp_PLC.write_Modbus_RTU_Coils(389,"1")
                    }
                }
            }
        }

        Item{
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.top: parent.top
            anchors.topMargin: 680
            width: 1000
            height: 200


            A_Label{
                anchors.left: parent.left
                anchors.top: parent.top
                anchors.topMargin: 10
                labelWidth: 300
                label_Data: qsTr("拖料架安全距离")
            }

            // A_TextInput{
            //     anchors.left: parent.left
            //     anchors.top: parent.top
            //     anchors.topMargin: 100
            //     inputWidth: 300
            //     // maxDataLength: 6
            //     showData: Cpp_PLC.Hold_Safe_Distance

            //     onInputFinished: {
            //         if(Number(inputData) < 0)
            //         {
            //             Cpp_PLC.write_Modbus_RTU_Hold_32(612,"0")
            //         }
            //         else if(Number(inputData) > 1000)
            //         {
            //             Cpp_PLC.write_Modbus_RTU_Hold_32(612,"1000")
            //         }
            //         else
            //         {
            //             Cpp_PLC.write_Modbus_RTU_Hold_32(612,inputData)
            //         }
            //     }
            // }

            A_NumberInput{
                anchors.left: parent.left
                anchors.top: parent.top
                anchors.topMargin: 100
                inputWidth: 300
                // maxDataLength: 6
                text: Cpp_PLC.Hold_Safe_Distance
                minValue: 0
                maxValue: 1000
                keyboard: holdSettingKeyboard

                onEditingFinished: function(value){
                    Cpp_PLC.write_Modbus_RTU_Hold_32(612,value)
                }

            }

            A_Button{
                anchors.right: parent.right
                anchors.rightMargin: 30
                anchors.top: parent.top
                anchors.topMargin: 100
                contentText_Data: Cpp_PLC.Hold_Exist ? qsTr("检测托料架") : qsTr("不检测托料架")
                contentText_Color: Cpp_PLC.Hold_Exist ? "red" : "black"
                // contentText_Fontsize: 40
                buttonWidth: 300

                onButtonClicked: {
                    if(Cpp_PLC.Hold_Exist)
                    {
                        Cpp_PLC.write_Modbus_RTU_Coils(499,"0")
                    }
                    else
                    {
                        Cpp_PLC.write_Modbus_RTU_Coils(499,"1")
                    }
                }
            }

        }


    }


    Rectangle{
        anchors.top: parent.top
        anchors.topMargin: 1340
        anchors.horizontalCenter: parent.horizontalCenter
        width: rootWidth - 20
        height: 200
        color: "transparent"
        border.width: 1


        A_Button{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.verticalCenter: parent.verticalCenter
            buttonWidth: 400
            contentText_Data: qsTr("左 移 动")
            // contentText_Fontsize: 40

            onButtonPressed: {
                Cpp_PLC.write_Modbus_RTU_Coils(21,"1")
            }

            onButtonReleased: {
                Cpp_PLC.write_Modbus_RTU_Coils(21,"0")
            }

        }

        A_Button{
            anchors.right: parent.right
            anchors.rightMargin: 30
            anchors.verticalCenter: parent.verticalCenter
            buttonWidth: 400
            contentText_Data: qsTr("右 移 动")
            // contentText_Fontsize: 40

            onButtonPressed: {
                Cpp_PLC.write_Modbus_RTU_Coils(22,"1")
            }

            onButtonReleased: {
                Cpp_PLC.write_Modbus_RTU_Coils(22,"0")
            }

        }


    }








}
